<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">设备名</span>
        <input type="text" class="summer-input" id="userName"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>设备ID</th>
		        <th>设备名称</th>
		        <th>手机号码</th>
		        <th>状态</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
		INIT_MATERIAL: basePath + "${common_url}initMaterial",
	   	DEL: basePath + "${common_url}del",
	   	INIT_EDIT_TIME: basePath + "${common_url}initEditTime",
	   	INIT_EDIT_GOODS: basePath + "${common_url}initEditGoods",
	   	INIT_ADVERT: basePath + "${common_url}initAdvert"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	$('#isDefaultAddress').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_T_USERS_ADDRESS_IS_DEFAULT_ADDRESS'
        });
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAdd']
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#userName').val('');
        	//$('#startTime').val(''); 
        	//$('#stopTime').val('');
        	
        	reloadTable();
        });
        
        //素材管理新增
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:material"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_MATERIAL + '?id=' + id;
        });	
        //编辑商品
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEditGoods"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="userId"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT_GOODS + '?id=' + id;
        });	
        //编辑时间
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEditTime"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="userId"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT_TIME + '?id=' + id;
        });	
        
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initAdvert"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="userId"]').attr('data-value');
            window.location.href = CONST_URL.INIT_ADVERT + '?id=' + id;
        });	
        
        createTable();
        
    });
    
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"userName": trimSpace($('#userName').val())
                	//"startTime": trimSpace($('#startTime').val()),
                	//"stopTime": trimSpace($('#stopTime').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"userName": trimSpace($('#userName').val())
                	//"startTime": trimSpace($('#startTime').val()),
                	//"stopTime": trimSpace($('#stopTime').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id'
    		     },
    		     {
    		    	 field: 'userId',
    		    	 hidden:true
    		     },
    		     {
    		    	 field: 'userName'
    		     },
    		     {
    		    	 field:'userPhone'
    		     },
    		     {
    		    	 field: 'status',
    		    	 render:function ( rowData ){
    		    		 if( "上线"==rowData.status ){
    		    			 return "<p style='color:green;'>上线</p>";
    		    		 }
    		    		 if( "离线"==rowData.status ){
    		    			 return "<p style='color:red;'>离线</p>";
    		    		 }
    		    	 }
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 4,    //显示数量
    		    			 permit: ['${name_english}:material','${name_english}:initEditGoods','${name_english}:initEditTime','${name_english}:initAdvert'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    	    ]
    	});
    }

   
   
</script>
</body>
</html>